package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

//JSHYW   用户   V_CM_GUAR_INFO_SUM_M  V_CM_TRADE_FIN_LOAN_DUBIL_SUM_M
type JSHYW struct {
	JLID       int        `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	Sjrq       *time.Time `gorm:"column:数据日期;type:date;"`
	Ssjg       string     `gorm:"column:所属机构;size:20"`
	Khzl       string     `gorm:"column:客户种类;size:20"`
	Jshjyzl    string     `gorm:"column:结售汇交易种类;size:20"`
	Yqdm       string     `gorm:"column:即远期代码;size:20"`
	Whskfsdm   string     `gorm:"column:外汇收款方式代码;size:20"`
	Whjsfsdm   string     `gorm:"column:外汇结算方式代码;size:20"`
	Zczh       string     `gorm:"column:支取账号;size:20"`
	Crzh       string     `gorm:"column:存入账号;size:20"`
	Zqbzdm     string     `gorm:"column:支取币种代码;size:20"`
	Zqbz       string     `gorm:"column:支取币种;size:20"`
	Crbzdm     string     `gorm:"column:存入币种代码;size:20"`
	Crbz       string     `gorm:"column:存入币种;size:20"`
	Zcje       float64    `gorm:"column:支取金额"`
	Crje       float64    `gorm:"column:存入金额"`
	Zcjezmy    float64    `gorm:"column:支取金额折美元"`
	Crjezmy    float64    `gorm:"column:存入金额折美元"`
	Zcfzxxldm  string     `gorm:"column:支取方现转种类代码;size:60"`
	Crfzxxldm  string     `gorm:"column:存入方现转种类代码;size:60"`
	Liushuihao string     `gorm:"column:流水号;size:10"`
	Jyhl       float64    `gorm:"column:交易汇率"`
	Pphl       float64    `gorm:"column:平盘汇率"`
	Khjgh      string     `gorm:"column:开户机构号"`
	Dyydfzm    string     `gorm:"column:当月邮电费收入折美"`
	Khjg       string     `gorm:"column:开户机构"`
	CUID       int        `gorm:"column:CUID"`
	YG1        string     `gorm:"-"`
	ZB1        *float64   `gorm:"-"`
	YG2        string     `gorm:"-"`
	ZB2        *float64   `gorm:"-"`
	YG3        string     `gorm:"-"`
	ZB3        *float64   `gorm:"-"`
	YG4        string     `gorm:"-"`
	ZB4        *float64   `gorm:"-"`
	YG5        string     `gorm:"-"`
	ZB5        *float64   `gorm:"-"`
}

//TableName User用户表名
func (JSHYW) TableName() string {
	return "V_CM_FX_SUM_M"
}

func (c *JSHYW) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_qtzb_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision("11:" + strconv.Itoa(c.JLID))
	if err != nil {
		return
	}
	i := 0
	if (diviMap == nil || len(diviMap) == 0) && c.Khzl == "对公客户" {
		share, err = cube.GetShare("comp_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	if (diviMap == nil || len(diviMap) == 0) && c.Khzl == "个人客户" {
		share, err = cube.GetShare("indi_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

// JSHYWEF G
func JSHYWEF() base.EntityFunc {
	return func() interface{} {
		entity := JSHYW{}
		return &entity
	}
}

//JSHYWESF GJ
func JSHYWESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []JSHYW
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(JSHYWEF(), JSHYWESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "JLID",
		TableName:     "T_COMP_QTZB_DIVI",
		EmidColName:   "emid",
		AcidColName:   "jlid",
		WhereCause:    "ywid=11",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("JSHYW", dao)
}
